package com.yiwei.zhh.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yiwei.zhh.R;
import com.yiwei.zhh.adapter.base.ItemAdapter;
import com.yiwei.zhh.model.SupportBankModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class BankSupportV2Adapter extends ItemAdapter<SupportBankModel.DataBean, BankSupportV2Adapter.DefaultHolder> {

    private Context context;

    public BankSupportV2Adapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_bank_support_v2, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        SupportBankModel.DataBean item = getItem(position);
        if (position != 0 && item.letter.equals(getItem(position - 1).letter)) {
            holder.txtTitle.setVisibility(View.GONE);
        } else {
            holder.txtTitle.setVisibility(View.VISIBLE);
        }
        holder.txtTitle.setText(item.letter);
        holder.txtName.setText(item.name);
        holder.txtType.setText("借记卡");
        holder.txtSingleDay.setText("单笔限额：" + getMoney(item.cut_noce_amount));
        holder.txtSingleMoney.setText("单日限额：" + getMoney(item.cut_daily_amount));
        if (item.name.contains("工商")) {
            Glide.with(context).load(R.mipmap.img_bank_gongshang).into(holder.imgIcon);
        } else if (item.name.contains("广发")) {
            Glide.with(context).load(R.mipmap.img_bank_guangfa).into(holder.imgIcon);
        } else if (item.name.contains("光大")) {
            Glide.with(context).load(R.mipmap.img_bank_guangda).into(holder.imgIcon);
        } else if (item.name.contains("广州")) {
            Glide.with(context).load(R.mipmap.img_bank_guangzhou).into(holder.imgIcon);
        } else if (item.name.contains("建设")) {
            Glide.with(context).load(R.mipmap.img_bank_jianshe).into(holder.imgIcon);
        } else if (item.name.contains("交通")) {
            Glide.with(context).load(R.mipmap.img_bank_jiaotong).into(holder.imgIcon);
        } else if (item.name.contains("平安")) {
            Glide.with(context).load(R.mipmap.img_bank_pingan).into(holder.imgIcon);
        } else if (item.name.contains("浦东")) {
            Glide.with(context).load(R.mipmap.img_bank_pufa).into(holder.imgIcon);
        } else if (item.name.contains("兴业")) {
            Glide.with(context).load(R.mipmap.img_bank_xingye).into(holder.imgIcon);
        } else if (item.name.contains("邮政")) {
            Glide.with(context).load(R.mipmap.img_bank_youzheng).into(holder.imgIcon);
        } else if (item.name.contains("浙商")) {
            Glide.with(context).load(R.mipmap.img_bank_zheshang).into(holder.imgIcon);
        } else if (item.name.contains("中国")) {
            Glide.with(context).load(R.mipmap.img_bank_zhongguo).into(holder.imgIcon);
        } else if (item.name.contains("中信")) {
            Glide.with(context).load(R.mipmap.img_bank_zhongxin).into(holder.imgIcon);
        } else if (item.name.contains("华夏银行")) {
            Glide.with(context).load(R.mipmap.huaxia).into(holder.imgIcon);
        } else if (item.name.contains("民生银行")) {
            Glide.with(context).load(R.mipmap.minsheng).into(holder.imgIcon);
        } else if (item.name.contains("农业银行")) {
            Glide.with(context).load(R.mipmap.nongye).into(holder.imgIcon);
        } else if (item.name.contains("上海银行")) {
            Glide.with(context).load(R.mipmap.shanghai).into(holder.imgIcon);
        } else if (item.name.contains("招商银行")) {
            Glide.with(context).load(R.mipmap.zhaoshang).into(holder.imgIcon);
        } else {
            Glide.with(context).load(R.mipmap.bank_default).into(holder.imgIcon);
        }


    }

    public String getMoney(String money) {
        if (Float.valueOf(money) >= 10000) {
            return (Float.valueOf(money) / 10000 + "").replace(".0", "") + "万";
        } else {
            return money.replace(".00", "").replace(".0", "");
        }
    }


    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_title)
        TextView txtTitle;
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_single_money)
        TextView txtSingleMoney;
        @BindView(R.id.view_center)
        View viewCenter;
        @BindView(R.id.txt_type)
        TextView txtType;
        @BindView(R.id.txt_single_day)
        TextView txtSingleDay;
        @BindView(R.id.content)
        RelativeLayout content;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
